$(function(){
    moon.info("欢迎来到XLink!","top");
    $("#submit").click(function(){
        $("#loginForm").validate("validate").done(function(result){
            if(result){
                $("#loginForm").ajaxSubmitForm(contextPath+"/users/login/validate").done(function(data){
                    console.log(data);
                    if(data.success){
                        console.log("success to login");
                        moon.info("登录成功","top");
                        window.location.href=contextPath+"/index.html";
                    }else{
                        moon.error("用户名或密码错误","top");
                    }
                }).fail(function(e){
                    console.log(e);
                    moon.error("服务出错，请稍后再试","top");
                });
            }
        });
    });
    $("#loginForm:input").on("keyup",function(e){
        if(e.keyCode == 13){
            $("#submit").trigger("click");
        }
    });
    $("#loginForm").validate({align:'bottom',theme:"darkblue"});
});